<?php

namespace yiike\store\model;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\store\model\TtycCategory;

/**
* TtycCategorySearch represents the model behind the search form about `yiike\store\model\TtycCategory`.
*/
class TtycCategorySearch extends TtycCategory
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'weid', 'cityid', 'parentid', 'isfirst', 'displayorder', 'enabled'], 'integer'],
            [['name', 'logo'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = TtycCategory::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'weid' => $this->weid,
            'cityid' => $this->cityid,
            'parentid' => $this->parentid,
            'isfirst' => $this->isfirst,
            'displayorder' => $this->displayorder,
            'enabled' => $this->enabled,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'logo', $this->logo]);

return $dataProvider;
}
}